package com.baidu.bos.web.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.baidu.bos.domain.Decidedzone;
import com.baidu.bos.service.IDecidedzoneService;
import com.baidu.bos.web.action.base.BaseAction;
import com.baidu.crm.domain.Customer;
import com.baidu.crm.service.CustomerService;
@Controller
@Scope("prototype")
public class DecidedzoneAction extends BaseAction<Decidedzone>{
	@Resource
	private IDecidedzoneService decidedzoneService;
	@Resource
	private CustomerService customerService;
	
	private String[] subareaids;
	//注入添加中分区
	public void setSubareaid(String[] subareaid) {
		this.subareaids = subareaid;
	}
	//保存定区
	public String save(){
		decidedzoneService.save(model,subareaids);
		return "list";
	}
	
	//分页查询
	public String pageQuery(){
		decidedzoneService.pageQuery(pageBean);
		this.writeObject2Json(pageBean);
		return NONE;
	}
	
	//查询所有未关联定区的客户
	public String findCustomerNoAssociation(){
		List<Customer> list = customerService.findnoassociationCustomers();
		this.writeObject2Json(list);
		return NONE;
	}
	
	//查询关联的客户
	public String findCustomerAssociation(){
		List<Customer> list = customerService.findhasassociationCustomers(model.getId());
		this.writeObject2Json(list);
		return NONE;
	}
	private Integer[] customerIds;
	public void setCustomerIds(Integer[] customerIds) {
		this.customerIds = customerIds;
	}
	//保存关联的客户
	public String assigncustomerstodecidedzone(){
		customerService.assignCustomersToDecidedZone(customerIds, model.getId());
		return "list";
	}
}
